package com.sky.controller.user;

import com.hxc.pay.NativePayTemplate;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.Result;
import com.sky.service.UserService.OrderService;
import com.sky.vo.OrderSubmitVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("userOrderController")
@RequestMapping("/user/order")
@Api(tags = "C端订单接口")
public class OrderController {
    private static final Logger log = LoggerFactory.getLogger(OrderController.class);
    @Resource
    OrderService orderService;
    @Resource
    NativePayTemplate nativePayTemplate;

    @GetMapping("getEstimatedDeliveryTime")
    @ApiOperation("预计送达时间")
    public Result getEstimatedDeliveryTime(String customerAddress, Integer shopId) {
        Result<String> estimatedDeliveryTime = orderService.getEstimatedDeliveryTime(customerAddress, shopId);
        return estimatedDeliveryTime;
    }

    @PostMapping("submit")
    @ApiOperation("用户下单")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        return orderService.insertSubmint(ordersSubmitDTO);
    }

    /**
                                                             */
    @GetMapping("/native")
    public Result<String> nativceCreateOrder(String outTradeNo) {
        log.warn("支付成功:{},微信通知",outTradeNo);
        String json = nativePayTemplate.createOrder(1, "刘总的订单", outTradeNo);
        return Result.success(json);
    }

}
